package lgs.hm.xml;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import lgs.hm.annotation.Main;
@Configuration
@ImportResource(locations= {"classpath:app.cfg.xml"})  //配置文件 ,可以写多个配置类
@Import(MyConfig1.class)  //导入另外一个javaConfig 
public class Xml {
	
	public static void main(String[] args) {
//		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Xml.class);
//		ApplicationContext ac = new ClassPathXmlApplicationContext("application.xml");
		//加容器
		//唯一缺点不支持注解
		//指定在xml配置文件的内路径
//		FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("classpath:app.cfg.xml");
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Xml.class);
		
		//从容器里面取
		Date date = (Date) context.getBean("mybirthday");  //按名称注入
		System.out.println(date);
		SimpleDateFormat format = context.getBean(SimpleDateFormat.class);
		System.out.println(format.format(date));
		
		Person person = context.getBean(Person.class);
		
		System.out.println(person);
		
		System.out.println(context.getBean(Cate.class));
		
		
		Calendar bean = context.getBean(Calendar.class);
		System.out.println(bean.getClass());
		
		System.out.println(context.getBean(MouMou.class));
		
	}

}
